<script setup lang="ts" name="SystemMailLogDetail">
import { DICT_TYPE } from '@/enums/dictEnums'
import { MailLogApi, MailLogType } from '@/api/system/messages/mail/log'

const { t } = useI18n() // 国际化
const visible = ref(false) // 弹窗的是否展示
const detailLoading = ref(false) // 表单的加载中
const detailData = ref({} as MailLogType) // 详情数据

/** 打开弹窗 */
const open = async (id: number) => {
  visible.value = true
  // 设置数据
  detailLoading.value = true
  try {
    detailData.value = await MailLogApi.detail(id)
  } finally {
    detailLoading.value = false
  }
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗
</script>

<template>
  <Dialog v-model="visible" :title="t('sys.messages.mail.log', 'detail')" height="500px" type="scroll" width="800px">
    <el-descriptions v-if="detailData" :column="1" border class="mr-10px">
      <el-descriptions-item :label="t('sys.messages.mail.log', 'sendTime')">
        {{ detailData.sendTime }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('sys.messages.mail.log', 'toMail')">
        {{ detailData.toMail }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('sys.messages.mail.log', 'userId')">
        {{ detailData.userId }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('sys.messages.mail.log', 'userType')" min-width="120">
        <dict-tag :type="DICT_TYPE.USER_TYPE" :value="detailData.userType" />
      </el-descriptions-item>
      <el-descriptions-item :label="t('sys.messages.mail.log', 'templateTitle')">
        {{ detailData.templateTitle }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('sys.messages.mail.log', 'templateContent')">
        <div v-html="detailData.templateContent" />
      </el-descriptions-item>
      <el-descriptions-item :label="t('sys.messages.mail.log', 'templateParams')">
        <el-input v-model="detailData.templateParams" :autosize="{ maxRows: 20 }" :readonly="true" type="textarea" />
      </el-descriptions-item>
      <el-descriptions-item :label="t('sys.messages.mail.log', 'sendStatus')" min-width="120">
        <dict-tag :type="DICT_TYPE.SYSTEM_MAIL_SEND_STATUS" :value="detailData.sendStatus" />
      </el-descriptions-item>
      <el-descriptions-item :label="t('sys.messages.mail.log', 'fromMail')">
        {{ detailData.fromMail }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('sys.messages.mail.log', 'templateId')">
        {{ detailData.templateId }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('sys.messages.mail.log', 'templateCode')">
        {{ detailData.templateCode }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('sys.messages.mail.log', 'templateNickname')">
        {{ detailData.templateNickname }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('sys.messages.mail.log', 'sendMessageId')">
        {{ detailData.sendMessageId }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('sys.messages.mail.log', 'sendException')">
        {{ detailData.sendException }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('common', 'createTime')">
        {{ detailData.create_time }}
      </el-descriptions-item>
    </el-descriptions>
  </Dialog>
</template>

<style scoped lang="scss"></style>
